# Maintainer: Martell Malone <martellmalone@gmail.com>

_realname=onig
_fullname=oniguruma
pkgbase=mingw-w64-${_fullname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_fullname}"
pkgver=6.9.5
pkgrel=1
pkgdesc="A regular expressions library (mingw-w64)"
arch=('any')
license=('BSD')
url="https://github.com/kkos/oniguruma"
options=('staticlibs')
source=("https://github.com/kkos/${_fullname}/releases/download/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        001-no-undefined.patch
        002-autoconf.patch)
sha256sums=('2f25cc3165e6da4b12dcabdb6b77c48f436d835e127ec2e3cad7abae9ea8e9a6'
            '3cef29d0ad118d1a83f017d81ac0c4095290131c57221b982f211240a63da3ff'
            '95ab626f9332c2f5fb6c811055baffc79e75789e9f244ac225093ba151a5a519')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  msg2 "001-no-undefined.patch"
  patch -p1 -i ${srcdir}/001-no-undefined.patch
  msg2 "002-autoconf.patch"
  patch -p1 -i ${srcdir}/002-autoconf.patch

  touch NEWS
  touch ChangeLog
  autoreconf -fi
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"

  ../${_realname}-${pkgver}/configure \
      --prefix=${MINGW_PREFIX} \
      --build=${MINGW_CHOST} \
      --host=${MINGW_CHOST} \
      --target=${MINGW_CHOST} \
      --enable-shared \
      --enable-static

  make
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make install DESTDIR="${pkgdir}"
}
